{include file="public/layout" /}
<body class="bodystyle" style="overflow-y: scroll; cursor: default; -moz-user-select: inherit;min-width:auto;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<style type="text/css">
    .ncap-form-default dt.tit {width: 120px;}
    .ncap-form-default div.bot {padding-left: 154px;}
</style>
{include file="notice/left" /}
<div class="page min-hg-c-10" style="min-width: auto; margin-left: 100px;">
    <form class="form-horizontal" id="postSmtpForm" method="post">
        <div class="flexigrid htitx">
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                            <tr>
                                <th class="sign w10"><div class="tc"></div></th>
                                <th class="w10"><div id="anchor-sms" class="tc">邮箱配置</div></th>
                                <th class=""><div class=""></div></th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>

        <div class="ncap-form-default htitx">
            <dl class="row">
                <dt class="tit">
                    <label for="smtp_server"><em>*</em>SMTP地址</label>
                </dt>
                <dd class="opt">
                    <input id="smtp_server" name="smtp_server" value="{$smtp.smtp_server|default=''}" class="input-txt" type="text" autocomplete="off" />
                    <p class="notic2">发送邮箱的smtp地址。如: smtp.qq.com或smtp.gmail.com</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="smtp_port"><em>*</em>SMTP端口</label>
                </dt>
                <dd class="opt">
                    <input id="smtp_port" name="smtp_port" value="{if condition="isset($smtp['smtp_port'])"}{$smtp['smtp_port']|default=''}{else /}465{/if}" class="input-txt" type="text" autocomplete="off"/>
                    <p class="notic2"><span style="color: red;">注意：大部分默认为465，具体请参看各STMP服务商的设置说明，极少部分是25或其他端口号。</span>
                    </p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="smtp_user"><em>*</em>发信邮箱账号</label>
                </dt>
                <dd class="opt">
                    <input id="smtp_user" name="smtp_user" value="{$smtp.smtp_user|default=''}" class="input-txt" type="text" autocomplete="off"/>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="smtp_pwd"><em>*</em>邮箱授权码</label>
                </dt>
                <dd class="opt">
                    <input id="smtp_pwd"  name="smtp_pwd" value="{$smtp.smtp_pwd|default=''}" class="input-txt" type="text" autocomplete="off"/>
                    <p class="notic2">使用发送邮件的邮箱授权码。具体请点击参看【<a href="JavaScript:void(0);" data-href="https://www.eyoucms.com/plus/view.php?aid=5552&origin_eycms=1" onclick="openFullframe(this,'获取邮箱授权码');">使用指南</a>】</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit"><em>*</em>管理员邮箱账号</dt>
                <dd class="opt">
                    <input value="{$smtp.smtp_from_eamil|default=''}" name="smtp_from_eamil" id="smtp_from_eamil" placeholder="多个邮箱可以用逗号隔开" class="input-txt" type="text" onkeyup="this.value=this.value.replace(/，/g,',');" onpaste="this.value=this.value.replace(/，/g,',')" autocomplete="off">
                    <input value="测试发送" class="input-btn" onclick="sendTestEmail();" type="button">
                    <p class="notic">多个邮箱可以用逗号隔开</p>
                </dd>
            </dl>

            <div class="bot">
                <a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green" onclick="submitSmtp();">保存</a>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    function submitSmtp() {
        var smtp_pwd = $.trim($('input[name="smtp_pwd"]').val());
        var smtp_user = $.trim($('input[name="smtp_user"]').val());
        var smtp_port = $.trim($('input[name="smtp_port"]').val());
        var smtp_server = $.trim($('input[name="smtp_server"]').val());
        var smtp_from_eamil = $.trim($('input[name="smtp_from_eamil"]').val());

        if (smtp_server != '' || smtp_user != '' || smtp_pwd != '' || smtp_from_eamil != '' || smtp_port != '') {
            if (smtp_pwd == '') {
                showErrorMsg('请输入邮箱授权码');
                $('input[name=smtp_pwd]').focus();
                return false;
            }
            else if (smtp_user == '' || !checkEmail(smtp_user)) {
                showErrorMsg('邮箱账号的格式不正确');
                $('input[name=smtp_user]').focus();
                return false;
            }
            else if (smtp_port == '') {
                showErrorMsg('请输入SMTP端口');
                $('input[name=smtp_port]').focus();
                return false;
            }
            else if (smtp_server == '') {
                showErrorMsg('请输入SMTP地址');
                $('input[name=smtp_server]').focus();
                return false;
            }
            else if (smtp_from_eamil == '') {
                showErrorMsg('请输入接收的邮件地址');
                $('input[name=smtp_from_eamil]').focus();
                return false;
            }
        }
        
        layer_loading("正在处理");
        $.ajax({
            url: "{:url('Notice/conf_smtp', ['_ajax'=>1])}",
            type: 'POST',
            data: $('#postSmtpForm').serialize(),
            dataType: 'JSON',
            success: function(res) {
                layer.closeAll();
                if (1 === parseInt(res.code)) {
                    showSuccessMsg(res.msg, 1500, function() {
                        window.location.reload();
                    });
                } else {
                    var icon = 5;
                    try{
                        if (res.data.icon) {
                            icon = res.data.icon;
                        }
                    }catch(e){}
                    showErrorAlert(res.msg, icon);
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }

    function sendTestEmail() {
        var email = $('#smtp_from_eamil').val();
        if (email == '') {
            showErrorMsg('接收的邮件地址不能为空！');
            $('input[name=smtp_from_eamil]').focus();
            return false;
        } else {
            layer_loading('正在发送');
            $.ajax({
                url : "{:url('Notice/send_test_email', ['_ajax'=>1])}",
                type: "POST",
                data: $('#postSmtpForm').serialize(),
                dataType: 'JSON',
                success: function (res) {
                    layer.closeAll();
                    if (1 === parseInt(res.code)) {
                        showSuccessMsg(res.msg, 1500, function() {
                            window.location.reload();
                        });
                    } else {
                        showErrorAlert(res.msg);
                    }
                },
                error: function(e) {
                    layer.closeAll();
                    showErrorAlert(e.responseText);
                }
            })
        }
    }
</script> 

{include file="public/footer" /}